/**
 * Copyright (C) 2011-2012 Luca Li Greci
 *
 * This file is part of pojo-creator
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.pojocreator.provider.number;

import com.pojocreator.provider.DataProvider;

/**
 * This class implements {@link DataProvider} to provide a unique sequence of number.
 * 
 * It is possible to create an instance of {@link SequentialNumber} to start with
 * 0 or with a custom number. 
 * 
 * @author Luca Li Greci
 */
public class SequentialNumber implements DataProvider < Number >{
    private int counter;

    /**
     * Create a new instance that starts with an sequence index 0.
     */
    public SequentialNumber() {
        this(0);
    }
    
    /**
     * Create a new instance of that starts
     * with a custom sequence index
     * 
     * @param startWith sequence starts index
     */
    public SequentialNumber(int startWith) {
        this.counter = startWith;
    }
    
    /**
     * Provide a number in a sequence
     * 
     * @return the next value in the sequence
     */
    @Override
    public Number data() {
        return Integer.valueOf(counter++);
    }
    
    /**
     * Return the type of element managed.
     * 
     * @return The type of element managed is <code>Integer.class</code> 
     */
    @Override
    public Class < Number > type() {
        return Number.class;
    }

    /**
     * The number of elements returned is 1
     * 
     * @return number of elements returned is 1
     */
    @Override
    public int size() {
        return 1;
    }
}
